package cn.flying.base.security.utils;

import javax.annotation.Resource;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @description: 密码转换密文处理工具类
 * @author: lvyong
 * @date: 2023年05月26日 12:36
 * @version: 1.0
 */
@Component
public class PasswordEncoderUtil {

    @Resource
    private PasswordEncoder passwordEncoder;

    /**
     * 加密密码转密文
     * @param pwd
     * @return
     */
    public String encrypt(String pwd) {
      return passwordEncoder.encode(pwd);
    }

    /**
     * 校验密码
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    public boolean match(String rawPassword, String encodedPassword) {
        return passwordEncoder.matches(rawPassword, encodedPassword);
    }

}
